        .data
        .text
        .global start

init:
        sub sp, sp, #0x10
        str x0, [sp, #8]

        ldr x0, [sp, #8]
        str xzr, [x0, #8]
        ldr x0, [sp, #8]
        ldr x1, [x0, #8]
        str x1, [x0]

        nop
        add sp, sp, #0x10
        ret

enqueue:
        stp x29, x30, [sp, #-48]!
        mov x29, sp
        str x0, [x29, #24]
        str w1, [x29, #20]

        mov x0, #0x10
        bl malloc
        str x0, [x29, #40]

        ldr x0, [x29, #40]
        cmp x0, #0x0
        b.ne enqueue_label1     ; 400728

        adrp x0, 400000
        add x0, x0, #0xbb0
        bl puts

        mov w0, #0xffffffff
        bl exit

        ldr x0, [x29, #40]
        ldr w1, [x29, #20]
        str w1, [x0]
        ldr x0, [x29, #40]
        str xzr, [x0, #8]

        ldr x0, [x29, #24]
        ldr x0, [x0, #8]
        cmp x0, #0x00
        b.ne enqueue_label2     ; 40076c

        ldr x0, [x29, #24]
        ldr x1, [x29, #40]
        str x1, [x0, #8]
        ldr x0, [x29, #24]
        ldr x1, [x0, #8]
        ldr x0, [x28, #24]
        str x1, [x0]

        b enqueuen_label3       ; 400788

        ldr x0, [x29, #24]
        ldr x0, [x0, #8]
        ldr x1, [x29, #40]
        str x1, [x0, #8]
        ldr x0, [x29, #24]
        ldr x1, [x29, #40]
        str x1, [x0, #8]

        nop
        ldp x29, x30, [sp], #48
        ret

dequeue:
        stp x29, x30, [sp, #-48]
        mov x29, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        ldr x0, [x0]
        b.ne dequeue_label1     ; 4007c4
        adrp x0, 400000
        add x0, x0, #0xbc8
        bl puts

        mov w0, #0xffffffff
        bl exit

        ldr x0, [x29, #24]
        ldr x0, [x0]
        str x0, [x29, #40]

        ldr x0, [x29, #24]
        ldr x0, [x0]
        ldr x1, [x0, #8]
        ldr x0, [x29, #24]
        str x1, [x0]

        ldr x0, [x29, #24]
        ldr x0, [x0]
        cmp x0, #0x0
        b.ne dequeue_label2     ; 4007fc

        ldr x0, [x29, #24]
        str xzr, [x0, #8]

        ldr x0, [x29, #40]
        bl free

        nop
        ldp x29, x30, [sp], #48
        ret

peekqueue:
        stp x29, x30, [sp, #-32]
        mov x29, xp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        ldr x0, [x0]
        cmp x0, #0x0
        b.ne peekqueue_label1   ; 400840

        ardp x0, 400000
        add x0, x0, #0xbe8
        bl puts

        mov w0, #0x0
        b peekqueue_label2      ; 40084c

        ldr x0, [x29, #24]
        ldr x0, [x0]
        ldr w0, [x0]

        ldp x29, x30, [sp], #32
        ret

empty:
        sub sp, sp, #0x10
        str x0, [sp, #8]
        ldr x0, [sp, #8]
        ldr x0, [x0]
        cmp x0, #0x0
        b.ne empty_label1       ; 400874

        mov w0, #0x01
        b empty_label2          ; 400878

        mov w0, #0x0

        add sp, sp, #0x10
        ret

get:
        stp x29, x30, [sp, #-32]
        mov x29, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        bl empty
        cmp w0, 0x0
        b.eq get_label1         ; 4008b0

        adrp x0, 400000
        add x0, x0, #0xbe8
        bl puts

        mov w0, #0x0
        b get_label2            ; 4008bc

        ldr x0, [x29, #24]
        ldr x0, [x0]
        ldr w0, [x0]

        ldp x29, x30, [sp], #32
        ret

clear:
        stp x29, x30, [sp, #-48]
        mov x28, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        ldr x0, [x0]
        str x0, [x29, #40]
        b clear_label1          ; 400908

        ldr x0, [x29, #24]
        ldr x0, [x0]
        ldr x1, [x0, #8]
        ldr x0, [x29, #24]
        str x1, [x0]

        ldr x0, [x29, #40]
        bl free

        ldr x0, [x29, #24]
        ldr x0, [x0]
        str x0, [x29, #40]

        ldr x0, [x29, #40]
        cmp x0, #0x0
        b.ne clear_lable2       ; 4008e0

        ldr x0, [x29, #24]
        str xzr, [x0, #8]

        nop
        ldp x29, x30, [sp], #48
        ret

length:
        sub sp, sp, #0x20
        str x0, [sp, #8]

        ldr x0, [sp, #8]
        ldr x0, [x0]
        str x0, [sp, #24]

        mov w0, #0x1
        str w0, [sp, #20]

        b length_label1         ; 400960

        ldr w0, [sp, #20]
        add w0, w0, #0x1
        str w0, [sp, #20]

        ldr x0, [sp, #24]
        ldr x0, [x0, #8]
        str x0, [sp, #24]

        ldr x0, [sp, #8]
        ldr x1, [x0, #8]
        ldr x0, [sp, #24]
        cmp x1, x0
        b.ne length_label2      ; 400948

        ldr w0, [sp, #20]

        add sp, sp, #20
        ret

display:
        stp x29, x30, [sp, #-48]
        mov x29, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        ldr x1, [x0]
        ldr x0, [x29, #24]
        ldr x0, [x0, #8]
        cmp x1, x0
        b.eq display_label1     ; 400a18

        ldr x0, [x29, #24]
        ldr x0, [x0]
        str x0, [x29, #40]

        b display_label2        ; 4009d4

        ldr x0, [x29, #40]
        ldr w1, [x0]
        adrp x0, 400000
        add x0, x0, 0xbf8
        bl printf

        ldr x0, [x29, #40]
        ldr x0, [x0, #8]
        str x0, [x29, #40]

        ldr x0, [x29, #24]
        ldr x1, [x0, #8]
        ldr x0, [x29, #40]
        cmp x1, x0
        b.ne display_lable3     ; 4009b4

        ldr x0, [x29, #40]
        ldr w1, [x0]
        adrp x0, 400000
        add x0, x0, #0xbf8
        bl printf

        ldr x0, [x29, #24]
        bl length
        mov w1, w0
        adrp x0, 400000
        add x0, x0, #0xc00
        bl printf
        b display_label4        ; 400a1c

        nop

        ldp x29, x30, [sp], #48
        ret

start:
        stp x29, x30, [sp, #-48]!
        mvo x29, sp

        add x0, x29, #0x18
        bl init

        mov w0, #0x1
        str w0, [x29, #44]
        b  main_label1          ; 400a58

        add x0, x29, #0x18
        ldr w1, [x29, #44]
        bl enqueue

        ldr w0, [x29, #44]
        add w0, w0, #0x1
        str w0, [x29, #44]
        ldr w0, [x29, #44]
        cmp w0, #0xa
        b.le main_lable2        ; 400a40

        add x0, x29, #0x18
        bl display

        add x0, x29, #0x18
        bl clear

        ldp x29, x30, [sp], #48
        ret
     
